package com.hb.game.pk.adpter;

import android.app.Activity;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.hb.game.pk.APP;
import com.hb.game.pk.R;
import com.hb.game.pk.utils.StringUtils;

import java.util.Map;
// 弃用
public class ChatListAdapter extends BaseQuickAdapter<Map, BaseViewHolder> {
    private Activity act;

    public ChatListAdapter(int layoutResId, Activity act) {
        super(layoutResId);
        this.act = act;
    }

    @Override
    protected void convert(BaseViewHolder helper, Map item) {
//        Glide.with(mContext).load(item.getUrl())
//                .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(5, 0, RoundedCornersTransformation.CornerType.ALL)))
//                .into(imageView);
        RelativeLayout rlRed = (RelativeLayout) helper.getView(R.id.rl_red);
        TextView tvZj = (TextView) helper.getView(R.id.tv_zj);
        TextView tvLq = (TextView) helper.getView(R.id.tv_lq);
        rlRed.setVisibility(View.GONE);
        tvZj.setVisibility(View.GONE);
        tvLq.setVisibility(View.GONE);
        if ((item.containsKey("m") && Float.parseFloat(item.get("m").toString()) == 1.0f) || !item.containsKey("m")) {
            rlRed.setVisibility(View.VISIBLE);
            String username = "";
            String money = "";
            int res = 0;
            if (!item.containsKey("m")) {
                res = getHeadRes(item.get("avatar").toString());
                username = item.get("username").toString();
                money = Float.parseFloat(item.get("money").toString()) / 100 + "";
            } else {
                Map<String, Object> data = (Map<String, Object>) item.get("data");
                res = getHeadRes(data.get("avatar").toString());
                username = data.get("username").toString();
                money = Float.parseFloat(data.get("money").toString()) / 100 + "";
            }
            helper.setImageResource(R.id.iv_head, res);
            helper.setText(R.id.tv_name, username);
            helper.setText(R.id.tv_money, money);
        } else if (item.containsKey("m") && Float.parseFloat(item.get("m").toString()) == 2.0f) {
            tvZj.setVisibility(View.VISIBLE);
            Map<String, Object> data = (Map<String, Object>) item.get("data");
            String name = data.get("username").toString();
            float money = Float.parseFloat(data.get("aword").toString());
//            tvZj.setText(SpannableStringUtils.getBuilder(name)
//                    .setForegroundColor(act.getResources().getColor(R.color.c_000000))
//                    .append("中奖")
//                    .append((money / 100) + "元").setForegroundColor(act.getResources().getColor(R.color.c_000000))
//                    .create());
            tvZj.setText(name + "中奖" + (money / 100) + "元");
        } else {
            tvLq.setVisibility(View.VISIBLE);
            Map<String, Object> data = (Map<String, Object>) item.get("data");
            String name = data.get("username").toString();
//            tvLq.setText(SpannableStringUtils.getBuilder(name)
//                    .setForegroundColor(act.getResources().getColor(R.color.c_000000))
//                    .append("领取了您的红包")
//                    .create());
            tvLq.setText(name + "领取了您的红包");
        }
    }

    private int getHeadRes(String avatar) {
        int res;
        String trim = StringUtils.getString(avatar);
        if (StringUtils.isEmpty(trim)) {
            res = R.mipmap.ic_head_normal;
        } else {
            int i = Integer.parseInt(trim);
            res = APP.headResource.get(i - 1);
        }
        return res;
    }
}
